home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
util1
/
wgrab.lha
/
RCS.RCSfiles
/
wgrab.c,v
next >
Wrap
Text File
|
1995-10-29
|
25KB
|
699 lines
head 1.2;
access;
symbols;
locks
aris:1.2; strict;
comment @ * @;
1.2
date 95.10.29.10.50.38; author aris; state Exp;
branches;
next 1.0;
1.0
date 95.10.13.09.25.31; author aris; state Exp;
branches;
next ;
desc
@Window Graber Main FIle
@
1.2
log
@Added Support For Screen Grabing
@
text
@/* $Id: wgrab.c,v 1.0 1995/10/13 09:25:31 aris Exp $
*/
#define CATCOMP_ARRAY
#include "wgrab.h"
#include "wgrab_cat.h"
#include <clib/commodities_protos.h>
#include <libraries/commodities.h>
#include <clib/locale_protos.h>
#include <libraries/locale.h>
#include <time.h>
#define _DEFPOPUP_ "lalt w"
#define _DEFWGRAB_ "lalt g"
#define _DEFSGRAB_ "lalt c"
struct Library *DataTypesBase,*IconBase;
struct Library *CxBase;
struct LocaleBase *LocaleBase;
enum {EID_AMODE=1,EID_DMODE,EID_FILENAME,EID_MHOTKEY,EID_GWHOTKEY,EID_GSHOTKEY,};
enum {ID_SAVE=1,
ID_USE,
ID_HIDE,
ID_ABOUT,
ID_QUIT,
ID_AMODEON,ID_AMODEOFF,
ID_DMODEON,ID_DMODEOFF,
MN_PROJECT,MN_SETTINGS,
ID_LOAD,ID_LOADENV,ID_LOADDEF,};
enum {HOTKEY_MAIN,HOTKEY_WGRAB,HOTKEY_SGRAB,};
APTR App,mwin,fname,dmode,amode,mhotkey,pfname,mn_main;
APTR gwhotkey,gshotkey,bt_save,bt_use,bt_quit,helptx;
CxObj *broker;
struct MsgPort *broker_port;
CxObj *cmhotkey,*cgwhotkey,*cgshotkey;
struct Catalog *mycatalog;
#define setmnlabel(number,label,comm) mn_data[number].nm_Label=lgetstring(label);\
mn_data[number].nm_CommKey=((comm)?lgetstring(comm):0)
#define menuBAR {NM_ITEM,NM_BARLABEL,0,0,0,(APTR)0}
/*FOLDER Compute Hotkey String
*/
char *mhotkeystr(void)
{
char *str=(char *)malloc(sizeof(char)*30);
char *ht=(char *)malloc(sizeof(char)*30);
get(mhotkey,MUIA_String_Contents,&ht);
sprintf(str,"rawkey %s",ht);
return(str);
}
char *gwhotkeystr(void)
{
char *str=(char *)malloc(sizeof(char)*30);
char *ht=(char *)malloc(sizeof(char)*30);
get(gwhotkey,MUIA_String_Contents,&ht);
sprintf(str,"rawkey %s",ht);
return(str);
}
char *gshotkeystr(void)
{
char *str=(char *)malloc(sizeof(char)*30);
char *ht=(char *)malloc(sizeof(char)*30);
get(gshotkey,MUIA_String_Contents,&ht);
sprintf(str,"rawkey %s",ht);
return(str);
}
/*END*/
void setnewhotkeys(void)
{
RemoveCxObj(cmhotkey);
RemoveCxObj(cgwhotkey);
RemoveCxObj(cgshotkey);
DeleteCxObj(cmhotkey);
DeleteCxObj(cgwhotkey);
DeleteCxObj(cgshotkey);
cmhotkey=HotKey(mhotkeystr(),broker_port,HOTKEY_MAIN);
cgwhotkey=HotKey(gwhotkeystr(),broker_port,HOTKEY_WGRAB);
cgshotkey=HotKey(gshotkeystr(),broker_port,HOTKEY_SGRAB);
AttachCxObj(broker,cmhotkey);
AttachCxObj(broker,cgwhotkey);
AttachCxObj(broker,cgshotkey);
}
/*FOLDER DoGrab
*/
void dograb(BOOL screen)
{
APTR req;
long ask,dmod;
char *filename=(char *)malloc(sizeof(char)*256);
char *file;
char *dir=(char *)malloc(sizeof(char)*256);
char *sfile;
struct TagItem AslTags[]={ASLFR_DoSaveMode,(ULONG)TRUE,
ASLFR_TitleText,(ULONG)"Chose Filename to Save to!",
ASLFR_InitialDrawer,(ULONG)NULL,
TAG_DONE,0};
Object *picture;
picture=GetPicture(screen);
if (picture) {
get(fname,MUIA_String_Contents,&sfile);
get(amode,MUIA_Selected,&ask);
if (ask) {
if (req=MUI_AllocAslRequest(0,NULL)) {
if (sfile) {
stcgfp(dir,sfile);
AslTags[2].ti_Data=(ULONG)dir;
}
if (MUI_AslRequest(req,AslTags)) {
filename=((struct FileRequester *)req)->fr_Drawer;
file=((struct FileRequester *)req)->fr_File;
AddPart(filename,file,256);
SavePicture(picture,filename);
MUI_FreeAslRequest(req);
return;
}
MUI_FreeAslRequest(req);
}
}
get(dmode,MUIA_Selected,&dmod);
if (dmod) {
struct tm *p;
long t;
time(&t);
p=localtime(&t);
stcgfp(filename,sfile);
sprintf(dir,"pic%d.%d.%d.iff",p->tm_hour,p->tm_min,p->tm_sec);
AddPart(filename,dir,256);
SavePicture(picture,filename);
return;
}
SavePicture(picture,sfile);
return;
}
MUI_Request(App,NULL,0,NULL,"*_OK","I Can`t Get Active Window !!",TAG_END);
}
/*END*/
/*FOLDER Locale lgetstring Function
*/
static STRPTR lgetstring(long id)
{
STRPTR builtin;
builtin=malloc(sizeof(char)*255);
strcpy(builtin,CatCompArray[id].cca_Str);
if (LocaleBase) {
strcpy(builtin,GetCatalogStr(mycatalog,id,builtin));
}
return(builtin);
}
/*END*/
/*FOLDER Broker Hook
*/
_HOOK_FUNC (long,cxhook,struct Hook *hook,APTR obj,CxMsg *cm)
{
switch (CxMsgType(cm)) {
case CXM_COMMAND:
switch (CxMsgID(cm)) {
case CXCMD_DISABLE:
case CXCMD_ENABLE:
break;
case CXCMD_KILL:
DoMethod(obj,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
break;
case CXCMD_APPEAR:
set(mwin,MUIA_Window_Open,TRUE);
break;
case CXCMD_DISAPPEAR:
set(mwin,MUIA_Window_Open,FALSE);
set(App,MUIA_Application_Iconified,TRUE);
break;
}
break;
case CXM_IEVENT:
switch (CxMsgID(cm)) {
case HOTKEY_MAIN:
DoMethod(obj,MUIM_Application_ReturnID,ID_HIDE);
break;
case HOTKEY_WGRAB:
dograb(FALSE);
break;
case HOTKEY_SGRAB:
dograb(TRUE);
break;
}
break;
}
return(0);
}
struct Hook cx_hook={
{NULL,NULL},
(void *)cxhook,
NULL,NULL
};
/*END*/
_HOOK_FUNC(void,HelpFunc,struct Hook *hook,Object *help,Object **objptr)
{
LONG udata=NULL;
if (*objptr) get(*objptr,MUIA_UserData,&udata);
set(helptx,MUIA_Text_Contents,udata);
}
/*FOLDER ReadArgs
*/
BOOL popup(long argc, UBYTE **argv)
{
UBYTE **tt;
BOOL retval=FALSE;
struct RDArgs *rarg;
long vnp;
long args[]={0};
if (argc==0) {
if (IconBase=OpenLibrary("icon.library",0)) {
tt=ArgArrayInit(argc,argv);
vnp=ArgInt(tt,"POPUP",-5);
if (vnp>-5) retval=TRUE;
ArgArrayDone();
CloseLibrary(IconBase);
}
}
else {
if (rarg=ReadArgs("POPUP/S",args,NULL)) {
retval=args[0];
FreeArgs(rarg);
}
}
return(retval);
}
/*END*/
void main(long argc,UBYTE **argv)
{
BOOL running=TRUE,pop;
long active,on;
ULONG signals;
static struct Hook help_hook={{0,0},(void *)HelpFunc,0,0};
struct NewMenu mn_data[]={
{NM_TITLE,"",0,0,0,(APTR)MN_PROJECT},
{NM_ITEM,"","",0,0,(APTR)ID_ABOUT},
menuBAR,
{NM_ITEM,"","",0,0,(APTR)ID_HIDE},
menuBAR,
{NM_ITEM,"","",0,0,(APTR)ID_QUIT},
{NM_TITLE,"",0,0,0,(APTR)MN_SETTINGS},
{NM_ITEM,"","",0,0,(APTR)ID_LOAD},
{NM_ITEM,"","",0,0,(APTR)ID_LOADENV},
{NM_ITEM,"","",0,0,(APTR)ID_LOADDEF},
menuBAR,
{NM_ITEM,"","",0,0,(APTR)ID_USE},
{NM_ITEM,"","",0,0,(APTR)ID_SAVE},
{NM_END,NULL,0,0,0,(APTR)0},
};
init();
if (!(DataTypesBase=OpenLibrary("datatypes.library",0)))
fail(NULL,"Can`t Open datatypes.library!!");
if (!(CxBase=OpenLibrary("commodities.library",0))) {
CloseLibrary(DataTypesBase);
fail(NULL,"Can`t Open commodities.library!!");
}
if (LocaleBase=(struct LocaleBase *)OpenLibrary("locale.library",0)) {
mycatalog=OpenCatalog(NULL,"wgrab.catalog",OC_BuiltInLanguage,(ULONG)"english",
OC_Version,(ULONG)1,
TAG_DONE,(ULONG)NULL);
}
setmnlabel(0,MSG_PROJECT,NULL);
setmnlabel(1,MSG_ABOUT,MSG_ABOUT_SC);
setmnlabel(3,MSG_HIDE,MSG_HIDE_SC);
setmnlabel(5,MSG_QUIT,MSG_QUIT_SC);
setmnlabel(6,MSG_SETTINGS,NULL);
setmnlabel(7,MSG_LOAD,NULL);
setmnlabel(8,MSG_LOADENV,NULL);
setmnlabel(9,MSG_LOADDEF,NULL);
setmnlabel(11,MSG_USE,NULL);
setmnlabel(12,MSG_SAVE,NULL);
pop=popup(argc,argv);
App = ApplicationObject,
MUIA_Application_Title,"WGrab",
MUIA_Application_Version,"$VER: WGrab 01.20 (29.10.95)",
MUIA_Application_Copyright,"© 1995 Aris Basic",
MUIA_Application_Author,"Aris Basic",
MUIA_Application_Description,"Saves Active Window As IFF Picture",
MUIA_Application_Base,"WGRAB",
MUIA_Application_BrokerHook,&cx_hook,
MUIA_Application_SingleTask,TRUE,
MUIA_Application_Window,mwin=WindowObject,
MUIA_Window_ID,MAKE_ID('M','A','I','N'),
MUIA_Window_Title,"WGrab 01.20",
MUIA_Window_NeedsMouseObject,TRUE,
MUIA_Window_Menustrip,mn_main=MUI_MakeObject(MUIO_MenustripNM,mn_data,0),
WindowContents,VGroup,
Child,HGroup,
Child,Label(lgetstring(MSG_ASK_BEFORE)),
Child,amode=ImageObject,
ImageButtonFrame,
MUIA_InputMode,MUIV_InputMode_Toggle,
MUIA_Image_Spec,MUII_CheckMark,
MUIA_Image_FreeVert,TRUE,
MUIA_Selected,TRUE,
MUIA_Background,MUII_ButtonBack,
MUIA_ShowSelState,FALSE,
MUIA_ExportID,EID_AMODE,
MUIA_UserData,lgetstring(MSG_ASK_HELP),
End,
Child,Label(lgetstring(MSG_FILENAME)),
Child,pfname=PopaslObject,
MUIA_Popstring_String,fname=StringObject,
StringFrame,
MUIA_String_MaxLen,256,
MUIA_String_Contents,"RAM:",
MUIA_ExportID,EID_FILENAME,
End,
MUIA_Popstring_Button,PopButton(MUII_PopFile),
MUIA_Disabled,TRUE,
MUIA_UserData,lgetstring(MSG_FILENAME_HELP),
ASLFR_SleepWindow,TRUE,
End,
Child,Label(lgetstring(MSG_DIR_MODE)),
Child,dmode=ImageObject,
ImageButtonFrame,
MUIA_InputMode,MUIV_InputMode_Toggle,
MUIA_Image_Spec,MUII_CheckMark,
MUIA_Image_FreeVert,TRUE,
MUIA_Selected,FALSE,
MUIA_Background,MUII_ButtonBack,
MUIA_ShowSelState,FALSE,
MUIA_ExportID,EID_DMODE,
MUIA_Disabled,TRUE,
MUIA_UserData,lgetstring(MSG_DIR_MODE_HELP),
End,
End,
Child,ColGroup(2),
Child,Label(lgetstring(MSG_HOTKEY_POPUP)),
Child,mhotkey=StringObject,
StringFrame,
MUIA_String_MaxLen,20,
MUIA_String_Contents,_DEFPOPUP_,
MUIA_ExportID,EID_MHOTKEY,
MUIA_UserData,lgetstring(MSG_HOTKEY_POPUP_HELP),
End,
Child,Label(lgetstring(MSG_HOTKEY_WGRAB)),
Child,gwhotkey=StringObject,
StringFrame,
MUIA_String_MaxLen,20,
MUIA_String_Contents,_DEFWGRAB_,
MUIA_ExportID,EID_GWHOTKEY,
MUIA_UserData,lgetstring(MSG_HOTKEY_WGRAB_HELP),
End,
Child,Label(lgetstring(MSG_HOTKEY_SGRAB)),
Child,gshotkey=StringObject,
StringFrame,
MUIA_String_MaxLen,20,
MUIA_String_Contents,_DEFSGRAB_,
MUIA_ExportID,EID_GSHOTKEY,
MUIA_UserData,lgetstring(MSG_HOTKEY_SGRAB_HELP),
End,
End,
Child,helptx=TextObject,
TextFrame,
MUIA_Text_PreParse,"\033c\033b",
MUIA_UserData,lgetstring(MSG_HELP_HELP),
End,
Child,HGroup,
Child,bt_save=SimpleButton(lgetstring(MSG_GUI_SAVE)),
Child,bt_use=SimpleButton(lgetstring(MSG_GUI_USE)),
Child,bt_quit=SimpleButton(lgetstring(MSG_GUI_QUIT)),
End,
End,
End,
End;
if (!App) {
if (mycatalog) CloseCatalog(mycatalog);
if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
if (CxBase) CloseLibrary(CxBase);
if (DataTypesBase) CloseLibrary(DataTypesBase);
fail(App,"Could Not Create Application");
}
DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENV);
get(amode,MUIA_Selected,&active);
if (!active) {
set(pfname,MUIA_Disabled,FALSE);
set(dmode,MUIA_Disabled,FALSE);
}
get(dmode,MUIA_Selected,&active);
if (active) set(amode,MUIA_Disabled,TRUE);
DoMethod(bt_quit,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
DoMethod(bt_save,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_SAVE);
DoMethod(bt_use,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_USE);
DoMethod(mwin,MUIM_Notify,MUIA_Window_MouseObject,MUIV_EveryTime,helptx,3,MUIM_CallHook,&help_hook,MUIV_TriggerValue);
DoMethod(amode,MUIM_Notify,MUIA_Selected,TRUE,App,2,MUIM_Application_ReturnID,ID_AMODEON);
DoMethod(amode,MUIM_Notify,MUIA_Selected,FALSE,App,2,MUIM_Application_ReturnID,ID_AMODEOFF);
DoMethod(dmode,MUIM_Notify,MUIA_Selected,TRUE,App,2,MUIM_Application_ReturnID,ID_DMODEON);
DoMethod(dmode,MUIM_Notify,MUIA_Selected,FALSE,App,2,MUIM_Application_ReturnID,ID_DMODEOFF);
DoMethod(mwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App,2,MUIM_Application_ReturnID,ID_HIDE);
get(App,MUIA_Application_Broker,&broker);
get(App,MUIA_Application_BrokerPort,&broker_port);
if (NULL==(cmhotkey=HotKey(mhotkeystr(),broker_port,HOTKEY_MAIN))) {
CloseLibrary(CxBase);
CloseLibrary(DataTypesBase);
fail(App,"Cannot Create Hotkeys!!");
}
if (NULL==(cgwhotkey=HotKey(gwhotkeystr(),broker_port,HOTKEY_WGRAB))) {
CloseLibrary(CxBase);
CloseLibrary(DataTypesBase);
fail(App,"Cannot Create Hotkeys!!");
}
if (NULL==(cgshotkey=HotKey(gshotkeystr(),broker_port,HOTKEY_SGRAB))) {
CloseLibrary(CxBase);
CloseLibrary(DataTypesBase);
fail(App,"Cannot Create Hotkeys!!");
}
AttachCxObj(broker,cmhotkey);
AttachCxObj(broker,cgwhotkey);
AttachCxObj(broker,cgshotkey);
if (pop) set(mwin,MUIA_Window_Open,TRUE);
else set(App,MUIA_Application_Iconified,TRUE);
while (running) {
switch (DoMethod(App,MUIM_Application_Input,&signals))
{
case MUIV_Application_ReturnID_Quit:
running=FALSE;
break;
case ID_AMODEON:
get(dmode,MUIA_Selected,&active);
if (active) set(dmode,MUIA_Selected,FALSE);
set(dmode,MUIA_Disabled,TRUE);
set(pfname,MUIA_Disabled,TRUE);
break;
case ID_AMODEOFF:
set(dmode,MUIA_Disabled,FALSE);
set(pfname,MUIA_Disabled,FALSE);
break;
case ID_DMODEON:
get(amode,MUIA_Selected,&active);
if (active) set(amode,MUIA_Selected,FALSE);
set(amode,MUIA_Disabled,TRUE);
break;
case ID_DMODEOFF:
set(amode,MUIA_Disabled,FALSE);
break;
case ID_SAVE:
DoMethod(App,MUIM_Application_Save,MUIV_Application_Save_ENVARC);
case ID_USE:
DoMethod(App,MUIM_Application_Save,MUIV_Application_Save_ENV);
setnewhotkeys();
case ID_HIDE:
get(App,MUIA_Application_Iconified,&on);
if(!on) {
set(mwin,MUIA_Window_Open,FALSE);
set(App,MUIA_Application_Iconified,TRUE);
}
else {
set(App,MUIA_Application_Iconified,FALSE);
set(mwin,MUIA_Window_Open,TRUE);
}
break;
case ID_LOAD:
DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENV);
case ID_LOADENV:
DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENVARC);
setnewhotkeys();
break;
case ID_LOADDEF:
set(amode,MUIA_Selected,TRUE);
set(dmode,MUIA_Disabled,TRUE);
set(amode,MUIA_Disabled,FALSE);
set(dmode,MUIA_Selected,FALSE);
set(pfname,MUIA_Disabled,TRUE);
break;
case ID_ABOUT:
MUI_Request(App,mwin,0,NULL,"*_OK","\033c\033bWGrab 01.20\n\033n"
"© Aris Basic\n\n"
"This Program Uses MUI \n© Stefan Stuntz",TAG_DONE);
break;
}
if (running && signals) Wait(signals);
}
set(mwin,MUIA_Window_Open,FALSE);
if (mycatalog) CloseCatalog(mycatalog);
if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
if (CxBase) CloseLibrary(CxBase);
if (DataTypesBase) CloseLibrary(DataTypesBase);
fail(App,NULL);
}
@
1.0
log
@Initial revision
@
text
@d1 1
a1 1
/* $Id$
d13 3
a15 2
#define _DEFPOPUP_ "lalt w"
#define _DEFGRAB_ "lalt g"
d21 1
a21 1
enum {EID_AMODE=1,EID_DMODE,EID_FILENAME,EID_MHOTKEY,EID_GHOTKEY,};
d31 1
a31 1
enum {HOTKEY_MAIN,HOTKEY_GRAB,};
d34 1
a34 1
APTR ghotkey,bt_save,bt_use,bt_quit,helptx;
d38 1
a38 1
CxObj *cmhotkey,*cghotkey;
d41 2
a42 2
#define setmnlabel(number,label,comm) mn_data[number].nm_Label=getstring(label);\
mn_data[number].nm_CommKey=((comm)?getstring(comm):0)
d45 2
a46 1
/// Compute Hotkey String
d55 9
a63 1
char *ghotkeystr(void)
d67 1
a67 1
get(ghotkey,MUIA_String_Contents,&ht);
d71 1
a71 1
////
d75 2
a76 1
RemoveCxObj(cghotkey);
d78 2
a79 1
DeleteCxObj(cghotkey);
d81 2
a82 1
cghotkey=HotKey(ghotkeystr(),broker_port,HOTKEY_GRAB);
d84 2
a85 1
AttachCxObj(broker,cghotkey);
d88 3
a90 2
/// DoGrab
void dograb(void)
d104 1
a104 1
picture=GetPicture();
d154 4
a157 3
////
/// Locale getstring Function
static STRPTR getstring(long id)
d167 1
a167 1
////
d169 2
a170 1
/// Broker Hook
d197 5
a201 2
case HOTKEY_GRAB:
dograb();
d213 1
a213 1
////
d220 2
a221 1
/// ReadArgs
d247 1
a247 1
////
d302 1
a302 1
MUIA_Application_Version,"$VER: WGrab 01.00 (04.10.95)",
d311 1
a311 1
MUIA_Window_Title,"WGrab 01.00",
d316 1
a316 1
Child,Label(getstring(MSG_ASK_BEFORE)),
d326 1
a326 1
MUIA_UserData,getstring(MSG_ASK_HELP),
d328 1
a328 1
Child,Label(getstring(MSG_FILENAME)),
d338 1
a338 1
MUIA_UserData,getstring(MSG_FILENAME_HELP),
d341 1
a341 1
Child,Label(getstring(MSG_DIR_MODE)),
d352 1
a352 1
MUIA_UserData,getstring(MSG_DIR_MODE_HELP),
d356 1
a356 1
Child,Label(getstring(MSG_HOTKEY_POPUP)),
d362 9
a370 1
MUIA_UserData,getstring(MSG_HOTKEY_POPUP_HELP),
d372 2
a373 2
Child,Label(getstring(MSG_HOTKEY_GRAB)),
Child,ghotkey=StringObject,
d376 3
a378 3
MUIA_String_Contents,_DEFGRAB_,
MUIA_ExportID,EID_GHOTKEY,
MUIA_UserData,getstring(MSG_HOTKEY_GRAB_HELP),
d381 5
a385 7
Child,HGroup,
Child,Label(getstring(MSG_HELP)),
Child,helptx=TextObject,
TextFrame,
MUIA_UserData,getstring(MSG_HELP_HELP),
End,
End,
d387 3
a389 3
Child,bt_save=SimpleButton(getstring(MSG_GUI_SAVE)),
Child,bt_use=SimpleButton(getstring(MSG_GUI_USE)),
Child,bt_quit=SimpleButton(getstring(MSG_GUI_QUIT)),
d432 1
a432 1
if (NULL==(cghotkey=HotKey(ghotkeystr(),broker_port,HOTKEY_GRAB))) {
d437 5
d444 2
a445 2
AttachCxObj(broker,cghotkey);
@